import { LayerManager } from "./LayerManager";
import { FrameTimer } from "../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../com/gengine/core/frame/TimerType";
import { ILayer } from "../../mvc/interfaces/ILayer";
import { NoticeItem } from "../view/msgbroad/NoticeItem";
import { ObjectPool } from "../../../com/gengine/utils/pools/ObjectPool";
import { Global } from "../../../com/gengine/global/Global";
type int = number;
//class MsgBroadCastImpl
    
    export  class MsgBroadCastImpl /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.layer = LayerManager.windowLayer;
            mouseEnabled = false;
            mouseChildren = false;
            var loc1=new Object /* flash.display.Sprite */();
            loc1.graphics.lineStyle(2, 16711680, 1);
            loc1.graphics.beginFill(16711680, 1);
            loc1.graphics.drawRect(0, 0, this.width, this.height + this._inDis);
            loc1.graphics.endFill();
            addChild(loc1);
            this.mask = loc1;
            this.cacheAsBitmap = true;
            this._timer = new FrameTimer();
            this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrame);
            this._timer.start();
            return;
        }

        public set layer(arg1: ILayer)
        {
            this._layer = arg1;
            this._layer.addPopUp(this);
            return;
        }

        /* internal  */onNoticeHide(arg1: NoticeItem): void
        {
            if (arg1.parent) 
            {
                removeChild(arg1);
            }
            arg1.dispose();
            ObjectPool.disposeObject(arg1, NoticeItem);
            return;
        }

        /* internal  */onLastItemHide(arg1: NoticeItem): void
        {
            if (contains(arg1)) 
            {
                removeChild(arg1);
            }
            arg1.dispose();
            ObjectPool.disposeObject(arg1, NoticeItem);
            return;
        }

        public showNotice(arg1: string): void
        {
            var loc1=false;
            var loc2=null;
            var loc3=null;
            if (!arg1 || arg1 == "") 
            {
                return;
            }
            if (this._layer) 
            {
                this._layer.setTop(this);
            }
            if (numChildren > 1) 
            {
                if (numChildren >= 4) 
                {
                    this._pushing = true;
                    (loc3 = getChildAt(1) as NoticeItem).easeHide(this.onLastItemHide);
                    this._pushing = false;
                }
                (getChildAt((numChildren - 1)) as NoticeItem).killInEase();
                loc1 = false;
            }
            else 
            {
                loc1 = false;
            }
            loc2 = ObjectPool.getObject(NoticeItem);
            addChild(loc2);
            loc2.updateData(arg1, this.onNoticeHide, this._inDis, loc1);
            this._needRedraw = true;
            return;
        }

        /* internal  */onEnterFrame(arg1: FrameTimer): void
        {
            if (this._needRedraw && !this._pushing) 
            {
                this._needRedraw = false;
                this.updatePxy();
            }
            return;
        }

        public updatePxy(): void
        {
            var loc3=null;
            var loc4=0;
            var loc1=0;
            var loc2=(numChildren - 1);
            while (loc2 > loc1) 
            {
                loc3 = getChildAt(loc2) as NoticeItem;
                if (loc3.hideIng) 
                {
                    --loc2;
                    continue;
                }
                if (loc3.disposed) 
                {
                    if (loc3.parent) 
                    {
                        removeChild(loc3);
                    }
                    --loc2;
                    continue;
                }
                loc3.x = (this.width - loc3.width) / 2;
                if (loc2 == (numChildren - 1)) 
                {
                    loc3.updatePosY(this.height - loc3.height - loc4);
                }
                else 
                {
                    loc3.updatePosY(this.height - loc3.height - loc4);
                }
                loc4 = (loc4 = loc4 + loc3.height) + this._gad;
                --loc2;
            }
            return;
        }

        public stageResize(): void
        {
            x = (Global.stage.stageWidth - this.width) / 2;
            y = 85;
            return;
        }

        public /* override */ get height(): number
        {
            return 60;
        }

        public /* override */ get width(): number
        {
            return 810;
        }

        /* internal */ /* var */_needRedraw: Boolean;

        /* internal */ /* var */_timer: FrameTimer;

        /* internal */ /* var */_pushing: Boolean;

        /* internal */ /* var */_inDis: int=70;

        /* internal */ /* var */_gad: int=0;

        /* internal */ /* var */_layer: ILayer;
    }
